using System.Data;
using System.Data.SqlClient;

namespace OrderManager.DataAccess.Extentions
{
    /// <summary>
    /// Contains some extention-methods for SqlCommand class
    /// </summary>
    public static class SqlCommadExtentions
    {
        /// <summary>
        /// Allows to add new parameter to SqlCommand entity.
        /// </summary>
        /// <param name="command">SqlCommand entity</param>
        /// <param name="name">Parameter name</param>
        /// <param name="value">Parameter value</param>
        /// <param name="type">Parameter type (as represents in SqlDbType enum)</param>
        public static void AddParameter(this SqlCommand command, string name, object value, SqlDbType type) {
            var parameter = command.CreateParameter();
            parameter.ParameterName = name;
            parameter.Value = value;
            parameter.SqlDbType = type;
            command.Parameters.Add(parameter);
        }
    }
}